package mobi.pooper;

import static mobi.pooper.Constants.NATIVE_HEIGHT;
import static mobi.pooper.Constants.NATIVE_WIDTH;
import mobi.pooper.db.IPicsDbAdapter;
import mobi.pooper.pictures.Picture;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.FlickScrollPane;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Label.LabelStyle;
import com.badlogic.gdx.scenes.scene2d.ui.tablelayout.Table;

public class StatScreen implements Screen {

	protected static final String TAG = StatScreen.class.getSimpleName();

	private Pooper pooper;
	private Stage stage;
	private BitmapFont font;
	private Table container;
	
	public StatScreen(Pooper pooper){
		this.pooper = pooper;
		
		stage = new Stage(NATIVE_WIDTH, NATIVE_HEIGHT, false);
		
		font = new BitmapFont();
		Gdx.input.setInputProcessor(stage);

		Gdx.graphics.setVSync(false);

		container = new Table();

		IPicsDbAdapter dba =((IPooperApplication)Gdx.app).getPicsDbAdapter();
		dba.open();
		Picture[] pics = dba.getAllItems();
		dba.close();

		for(int i = 0; i < pics.length; i++){
			container.add(new Label(Integer.toString(i), new LabelStyle(font, Color.GRAY))).expandX().fillX();
			container.add(new Label("Файл: " + pics[i].getName(), new LabelStyle(font, Color.YELLOW))).expandX().fillX();
			container.add(new Label("Успехов: " + pics[i].getSuccessesNumber(), new LabelStyle(font, Color.GREEN))).expandX().fillX();
			container.add(new Label("Ошибок: " + pics[i].getFailsNumber(), new LabelStyle(font, Color.RED))).expandX().fillX();
			container.row();
		}
		
		FlickScrollPane scroll = new FlickScrollPane(container);
		scroll.width = NATIVE_WIDTH;
		scroll.height = NATIVE_HEIGHT;
		
		stage.addActor(scroll);
	}

	@Override
	public void dispose() {
		stage.dispose();
		font.dispose();
	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void render(float arg0) {
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		stage.act(Gdx.graphics.getDeltaTime());
		stage.draw();
	}

	@Override
	public void resize(int width, int height) {
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void show() {
		// TODO Auto-generated method stub

	}
}
